/*
 The long-term impact of a resource-based fiscal windfall: evidence from the Peruvian canon
 --------------------------------------------------------

 
Author: F. Aragon and H. Winkler
Date: October, 2023
Replication file

*/

*install additional ADOs
ssc install psmatch2, replace
ssc install ivreghdfe, replace

    
 *DATASET 
 use "data.dta", clear
 
 
 *A.  CREATE ADDITIONAL VARIABLES
 ********************************
  {
  
 *geogrpahical identifiers
 gen dep_id=int(ubigeo/10000)
 gen prov_id=int(ubigeo/100 )
 
 gen is_limametro=(prov_id==1501 | dep_id==7)
 
 *define sample
 gen sample=1 
 replace sample= 0 if is_limametro==1 | dep_id == 24 | dep_id== 23
 *drop metropolitan lma and two major land custom borders tumbes and tacna
 *results robus to 
 
*reformat trnsafer and revneue to be in thousands
*other revenue (but FCM and CAnon)

foreach x of varlist totalrevenue* foncomun* canonaduanas*{
	replace `x'=`x'/1000
	
}
forvalues i=1998/2018{
	gen otherrevenue_`i'=totalrevenue_`i' - foncomun_`i' - canonaduanas_`i'
	gen totalrevenue_nocanon_`i'=totalrevenue_`i'  - canonaduanas_`i'
}



*Cumulative transfer (totao and per capita census pop) 1998-2007 and 2008-2017
*Census 2007 and 2017 

foreach x in totalrevenue  foncomun  canonaduanas otherrevenue totalrevenue_nocanon taxes recaud {
	cap egen cum_`x'_0916=rsum(`x'_2009 `x'_2010 `x'_2011 `x'_2012 `x'_2013 `x'_2014 `x'_2015  `x'_2016  )

		cap egen cum_`x'_0918=rsum(`x'_2009 `x'_2010 `x'_2011 `x'_2012 `x'_2013 `x'_2014 `x'_2015  `x'_2016 `x'_2017 `x'_2018 )
	
		cap egen cum_`x'_9807=rsum(`x'_1998 `x'_1999 `x'_2000 `x'_2001 `x'_2002 `x'_2003 `x'_2004  `x'_2005  `x'_2006 `x'_2007 )
	
		cap egen cum_`x'_9807_0916 = rsum(cum_`x'_0916 cum_`x'_9807)
	
	
	 	cap gen avg_`x'_0916_pc=(cum_`x'_0916 / cpv17_pop)/8
	 	cap label var avg_`x'_0916_pc "Average annual per capita amount (000s), period 2009-2016: `x'"
	 
	 	cap gen avg_`x'_0918_pc=(cum_`x'_0918 / cpv17_pop)/10
	 	cap label var avg_`x'_0918_pc "Average annual per capita amount (000s), period 2009-2018: `x'"
	 
	 	cap gen avg_`x'_9807_pc=(cum_`x'_9807 / cpv17_pop)/10
	 	cap label var avg_`x'_9807_pc "Average annual per capita amount (000s), period 1998-2007: `x'"

			cap  gen avg_`x'_9807_0916_pc=(cum_`x'_9807_0916/ cpv17_pop)/18
	 	cap label var avg_`x'_9807_0916_pc "Average annual per capita amount (000s), period 1998-2016 excl. 2008: `x'"

	  
	 
}

foreach x of varlist avg_* cpvp_pop_* {
	cap drop ln_`x'
	cap gen ln_`x'=ln(`x')
	
} 

***********************
*indicators of CAnon decil

cap drop canonaduanas_decil_0916
xtile canonaduanas_decil_0916= avg_canonaduanas_0916_pc if sample==1, n(10)

cap drop canonaduanas_decil_9807_0916
xtile canonaduanas_decil_9807_0916= avg_canonaduanas_9807_0916_pc if sample==1, n(10)

cap drop canonaduanas_quartil_0916
xtile canonaduanas_quartil_0916= avg_canonaduanas_0916_pc if sample==1, n(4)


cap drop canonaduanas_quartil_9807_0916
xtile canonaduanas_quartil_9807_0916= avg_canonaduanas_9807_0916_pc if sample==1, n(4)

 *measures of high canon
 gen high_canon_0916_p50=(canonaduanas_decil_0916>=5)
 gen high_canon_9807_0916_p50=(canonaduanas_decil_9807_0916>=5)

 gen high_canon_0916_p75=(canonaduanas_quartil_0916>=4)
 gen high_canon_9807_0916_p75=(canonaduanas_quartil_9807_0916>=4)

  gen high_canon_0916_p90=(canonaduanas_decil_0916==10)
  gen high_canon_9807_0916_p90=(canonaduanas_decil_9807_0916==10)

 
******************

 *NOTE: 2008 has lots of missin, 1300 munic instead of 1800. 
 *data missing from source. I will drop this year in analysis...
 
 *change in poverty and inequality measures?
 *start with access to public services
 *electricity, piped water, indoor sanitation
 *comapre census 2007 to 2017
 
 *mesaures of coverage
 
 gen pipedwater_17 = cpv17_water_0/( cpv17_water_0 +cpv17_water_1 +cpv17_water_2 +cpv17_water_3 +cpv17_water_4 +cpv17_water_5 +cpv17_water_6 +cpv17_water_7 +cpv17_water_8)
 gen pipedwater_07=cpvp_piped_water_07
 gen pipedwater_93=cpvp_piped_water_93
  
 
 gen electricity_17=cpv17_elec_1 / (cpv17_elect_0+cpv17_elec_1)
  gen electricity_07 = cpvp_electricity_07
   gen electricity_93 = cpvp_electricity_93

 gen sewage_17=cpv17_sewage_0 /(cpv17_sewage_0 +cpv17_sewage_1 +cpv17_sewage_2 +cpv17_sewage_3 +cpv17_sewage_4 +cpv17_sewage_5 +cpv17_sewage_6 +cpv17_sewage_7)
 gen sewage_07= cpvp_indoorsewage_07
  gen sewage_93=  cpvp_indoorsewage_93

 
 gen poor_18 = ineq18_poor
 gen poor_99 = fonc_xpoor_ab/100
 gen poor_07 = pov07_poor/100
 
 
gen D_ln_pop_93_17=ln(cpv17_pop) - ln(cpvp_pop_93)
gen ln_pop93=ln(cpvp_pop_93)
gen ln_area=ln(areakm2)
gen share_rural93=cpvp_pop_rural_93/(cpvp_pop_urban_93 +cpvp_pop_rural_93)
gen share_rural07=cpvp_pop_rural_07/(cpvp_pop_urban_07 + cpvp_pop_rural_07)

gen density93=cpvp_pop_93/areakm2
gen literacy_17= cpv17_readwrite_tot_1/(cpv17_readwrite_tot_1+ cpv17_readwrite_tot_0)
gen D_nbi0_93_07= cpvp_share_nbi0_asset_07 - cpvp_share_nbi0_93 

tab dep_id, gen(dumdep)
 
 *renamu data
 egen n_workers_18=rsum(n_func_18 n_prof_18 n_tecn_18 n_auxi_18 n_obre_18)
  egen n_workers_99=rsum(n_func_99 n_prof_99 n_tecn_99 n_auxi_99 n_obre_99)

  gen share_func18=n_func_18 / n_workers_18
    gen share_func99=n_func_99 / n_workers_99

	  gen share_prof18=n_prof_18 / n_workers_18
	  gen share_prof99=n_prof_99 / n_workers_99

 
 
*  UPDATED FEb 2022
 
*create outcome vars

gen pipedwater= pipedwater_17
gen D_pipedwater=pipedwater_17 - pipedwater_93
 
gen sewage=sewage_17
gen D_sewage =sewage_17 - sewage_93
 
gen electricity=electricity_17
gen D_electricity =electricity_17 - electricity_93
 
 gen poor = poor_18
 gen D_poor= poor_18 - poor_07

 
gen gini=ineq18_gini  
gen D_gini=ineq18_gini - pov07_gini


 gen population=ln(cpv17_pop)
 gen D_population= ln(cpv17_pop) - ln_pop93

 
 gen literacy=literacy_17
 gen D_literacy= literacy_17 - cpvp_share_literacy_93

  gen share_func=share_func18
 gen D_share_func= share_func18 - share_func99
 
   gen share_prof=share_prof18
 gen D_share_prof= share_prof18 - share_prof99
 
 
  /*
   gen n_workers=ln(n_workers_18)
 gen D_n_workers=ln(n_workers_18) - ln(n_workers_99)
 gen ln_n_workers_99=ln(n_workers_99)
  sum ln_n_workers_99 if sample==1
 gen N_n_workers =D_n_workers/r(sd)
 
 
 gen n_cars =n_cars_18
 gen D_n_cars=n_cars_18 - n_cars_99
 sum share_func99 if sample==1
 gen N_share_func =D_share_func/r(sd)
 
 
 gen n_heavymachin=n_heavymachin_18
 gen D_n_heavymachin=n_heavymachin_18 - n_heavymachin_99
 
 gen n_computer=n_computer_18
 gen D_n_computer=n_computer_18 - n_computer_99
 */
 
 gen n_gestioninfo4  = n_gestioninfo4_18 
 gen D_n_gestioninfo4 = n_gestioninfo4_18- n_gestioninfo4_99
 
 *normlized per capita
 
 gen n_workers_99pc		=	n_workers_99 / cpvp_pop_93*1000
 gen n_computer_99pc	= 	n_computer_99/ cpvp_pop_93*1000
 gen n_cars_99pc		=	n_cars_99 / cpvp_pop_93*1000
 gen n_heavymachin_99pc	=	n_heavymachin_99 / cpvp_pop_93*1000
 
  gen n_prof_99pc		=	n_prof_99 / cpvp_pop_93*1000
   gen n_profpc= n_prof_18 / cpv17_pop*1000
 gen D_n_profpc= n_prof_18 / cpv17_pop*1000 - n_prof_99 / cpvp_pop_93*1000
 
  gen n_workerspc= n_workers_18 / cpv17_pop*1000
 gen D_n_workerspc= n_workers_18 / cpv17_pop*1000 - n_workers_99 / cpvp_pop_93*1000
 
  gen n_computerpc=n_computer_18 / cpv17_pop*1000
   gen D_n_computerpc=n_computer_18/ cpv17_pop*1000  - n_computer_99/ cpvp_pop_93*1000
 
  gen n_carspc= n_cars_18 / cpv17_pop*1000
 gen D_n_carspc= n_cars_18 / cpv17_pop*1000 - n_cars_99 / cpvp_pop_93*1000
 
   gen n_heavymachinpc= n_heavymachin_18 / cpv17_pop*1000
 gen D_n_heavymachinpc= n_heavymachin_18 / cpv17_pop*1000 - n_heavymachin_99 / cpvp_pop_93*1000
 
 **finances
 egen avg_ownrev_0918_pc=rsum( avg_recaud_0918_pc avg_taxes_0918_pc)
  egen avg_ownrev_0916_pc=rsum( avg_recaud_0916_pc avg_taxes_0916_pc)

   replace avg_ownrev_0918_pc=avg_ownrev_0918_pc/1000
      replace avg_ownrev_0916_pc=avg_ownrev_0916_pc/1000

 *
 * created "standardized variables' by dividing by SD in  year (or basleine if Differnce)  so change can be interpreted in terms of % change....
*----------------------

  foreach y in ///
    pipedwater sewage electricity   poor gini population literacy  ///
 n_workerspc  share_func     n_computerpc ///
 n_carspc n_heavymachinpc  n_gestioninfo4   ///
 avg_totalrevenue_0916_pc   avg_ownrev_0916_pc  need_tech_18 need_train_18   {

		sum `y' if sample==1
		gen N_`y' = (`y'-r(mean))/r(sd)
}


* Obtain First differneces of normlaized values
*equivalent to standardize each year with respect to basline and then taking differences
*normalized with respect to baseline year


 sum pipedwater_93 if sample==1
gen N_D_pipedwater=D_pipedwater/r(sd) /*normalized by SD in base year*/

sum sewage_93 if sample==1
gen N_D_sewage=D_sewage/r(sd) /*normalized by SD in base year*/

sum electricity_93 if sample==1
gen N_D_electricity =D_electricity/r(sd)

  sum poor_07 if sample==1
 gen N_D_poor =D_poor/r(sd)

 sum pov07_gini if sample==1
 gen N_D_gini =D_gini/r(sd)

 sum ln_pop93 if sample==1
 gen N_D_population =D_population/r(sd)

  sum cpvp_share_literacy_93 if sample==1
 gen N_D_literacy =D_literacy/r(sd)
 
  sum share_func99 if sample==1
 gen N_D_share_func =D_share_func/r(sd)
 
   sum n_gestioninfo4_99 if sample==1
  gen N_D_n_gestioninfo4 = D_n_gestioninfo4/r(sd)

   sum n_workers_99pc if sample==1
      gen N_D_n_workerspc= D_n_workerspc/r(sd)

  sum n_computer_99pc if sample==1
  gen N_D_n_computerpc = D_n_computerpc/r(sd)
  
  sum n_cars_99pc if sample==1
  gen N_D_n_carspc=D_n_carspc/r(sd)
  
  sum n_heavymachin_99pc if sample==1
  gen N_D_n_heavymachinpc=D_n_heavymachinpc/r(sd)
  
**create index of access to public services
egen N_index_pubserv=rmean(N_pipedwater N_sewage N_electricity)
egen N_D_index_pubserv =rmean(N_D_pipedwater N_D_sewage N_D_electricity)

*create index of poverty and inequality
egen N_index_povineq = rmean(N_poor N_gini)
egen N_D_index_povineq = rmean(N_D_poor N_D_gini)

*create index of munic inputs (workers, cars, management tools)
 egen N_index_municinputs = rmean ( N_n_workerspc        N_n_computerpc  N_n_carspc N_n_heavymachinpc  N_n_gestioninfo4)
 egen N_D_index_municinputs = rmean ( N_D_n_workerspc        N_D_n_computerpc  N_D_n_carspc N_D_n_heavymachinpc  N_D_n_gestioninfo4 )

 *Municipal revenue
 
 sum avg_totalrevenue_9807_pc if sample==1
  gen N_D_avg_totalrevenue_0916_pc = (avg_totalrevenue_0916_pc - avg_totalrevenue_9807_pc)/r(sd)
  gen  D_avg_totalrevenue_0916_pc = (avg_totalrevenue_0916_pc - avg_totalrevenue_9807_pc) 
   
 *training needs
 
 sum need_tech_99 if sample==1
   gen N_D_need_tech_18 = (need_tech_18 - need_tech_99)/r(sd)
   gen  D_need_tech_18 = (need_tech_18 - need_tech_99) 

  sum need_train_99 if sample==1
   gen N_D_need_train_18 = (need_train_18 - need_train_99)/r(sd)
   gen  D_need_train_18 = (need_train_18 - need_train_99) 

   gen  D_high_tech18 = (high_tech18 - high_tech99) 
   gen  D_high_train18 = (high_train18 - high_train99) 

   
 
*generate IV
*1. average measure of trasnfer  in other districts of province 
foreach x of varlist high_canon_9807_0916_p75 avg_canonaduanas_9807_0916_pc density93 share_rural93 cpvp_pop_93  cpvp_share_nbi1_93 high_canon_9807_0916_p90  {
	cap drop sum_X n_X 
	cap drop `x'_J
	bys prov_id: egen sum_X= sum(`x')
	bys prov_id: egen n_X= count(`x')
	gen `x'_J=(sum_X - `x')/n_X
}
cap gen ln_cpvp_pop_93_J=ln(cpvp_pop_93_J)
  gen ln_avg_canon_9807_0916_pc_J=ln(avg_canonaduanas_9807_0916_pc_J)
 
 
*Insicator of "intensity" how many years disitrct receibe high levels of canon


cap drop tmp*
forvalues i=1998/2016{
	gen tmp_canonpc_`i'=canonaduanas_`i'/cpv17_pop
	xtile tmp_canonpc_`i'_q4= tmp_canonpc_`i' if sample==1, n(4)
	gen tmp_high_`i'=(tmp_canonpc_`i'_q4==4)
}

drop tmp_high_2008

egen highcanon_n=rmean(tmp_high_*)

***interaction terms
*********************

gen high_tech18=(need_tech_18>0.5)
gen high_tech99=(need_tech_99>0.5)

gen high_train18=(need_train_18>0.5)
gen high_train99=(need_train_99>0.5)

egen highneed=rmax(high_tech99  high_train99)

gen sierra=(cpvp_dominio>=4 & cpvp_dominio<=6)

// sum need_tech_99 if sample==1
// gen highneed=0
// replace highneed=1 if need_tech_99>r(p50) 
//
// sum   need_train_99 if sample==1, de
// replace highneed=1 if  need_train_99>r(p50) 
//
  sum   share_prof99 if sample==1, de
  replace low_shareprof99=1 if  share_prof99<r(p50) 


sum share_rural93 if sample==1, de
gen highrural=(share_rural93>r(p50))

sum cpvp_share_seccom_07 if sample==1, de
gen lowsec=(cpvp_share_seccom_07<r(p50))

gen T=high_canon_9807_0916_p75

gen Txhighneed=T*highneed
gen Txhighrural=T*highrural
gen Txsierra=T*sierra
gen Txlowsec=T*lowsec
gen Txshareprof99=T*share_prof99
**transport per capita

foreach x of varlist rep_pistas_m2 con_pistas_m2 rep_veredas_m2 con_veredas_m2 rep_rural_km con_rural_km{
 gen `x'_pc=`x'/cpv17_pop
}




  }

 


 
 
 
 
 *B.  TABLES AND FIGURES
 ********************************
 
global var_geo = "density93   slope  altitude  ruggedness_index "
global var_93 = "ln_pop93   cpvp_share_literacy_93 cpvp_share_spanish_93 cpvp_nacioaqui_93  share_rural93 "
global var_07=" ln_cpvp_pop_07 cpvp_share_noeduc_07 share_rural07" 
 global othertrasnfers0916="ln_avg_foncomun_0916_pc  ln_avg_otherrevenue_0916_pc "
 global treatment="high_canon_9807_0916_p75"
 *global treatment="high_canon_0916_p75"

 
{
*FIGURE 1
****************

sum totalrevenue*
sum foncomun* 
sum canonaduanas*


*FIGURE 2
****************

table canonaduanas_decil_9807_0916 if sample==1, c(mean avg_canonaduanas_9807_0916_pc   mean avg_foncomun_9807_0916_pc mean avg_otherrevenue_9807_0916_pc mean avg_totalrevenue_9807_0916_pc) 
 
 
 
*FIGURE 2
***************

table canonaduanas_decil_9807_0916 if sample==1, c(mean pipedwater_17 mean electricity_17 mean sewage_17     )


  
* TABLES 1 and 2
***********************
 
global varsum_pre= "share_rural93 cpvp_pop_93 pipedwater_93 sewage_93 electricity_93 poor_07 pov07_gini  avg_totalrevenue_9807_pc   avg_canonaduanas_9807_pc   n_workers_99pc   share_prof99         n_cars_99pc n_heavymachin_99pc  n_gestioninfo4_99 need_tech_99 high_tech18  need_train_99 high_train99"
global varsum_post="sierra altitude  ruggedness_index  cpv17_pop pipedwater sewage electricity     poor gini   avg_totalrevenue_0916_pc   avg_canonaduanas_0916_pc   n_workerspc  share_prof           n_carspc n_heavymachinpc  n_gestioninfo4 need_tech_18 high_tech18 need_train_18 high_train18"
  
  
  global varsum_pre=" high_tech99   high_train99"
  global varsum_post=" high_tech18   high_train18"
*Columns 1-3
sum $varsum_pre  $varsum_post   if sample==1   
sum $varsum_pre  $varsum_post  if sample==1   &  $treatment==1
sum $varsum_pre  $varsum_post   if sample==1   &  $treatment==0


*Column 4
local optionreplace="replace"
foreach x of varlist $varsum_pre $varsum_post  {
   
		quietly reg  `x' $treatment if sample==1
		outreg2 $treatment  using table_pval.xls, bdec(3)  stats(pval) `optionreplace'
		local optionreplace=""
   }
    
 

  
* TABLE  3
***********************

 

 local optionreplace="replace"
  foreach y in  pipedwater sewage electricity    poor gini          {
 
 		*OLS
		reghdfe    `y'     $treatment       $var_93   $var_geo     if sample==1  , abs(i.dep_id)  vce(robust)
				outreg2 $treatment  using table_main.xls, bdec(3)   `optionreplace'
				local optionreplace=""
		*OLS +boundary FE
		reghdfe    `y'     $treatment  $var_93   $var_geo if sample==1  , abs(i.boundary_id)  vce(robust)
				outreg2 using table_main.xls, bdec(3)   `optionreplace'
		*PSM
		bootstrap r(ate): psmatch2         $treatment   $var_93   $var_geo    if sample==1    , n(4) outcome(`y') common  ate
				outreg2 using table_main.xls, bdec(3)   `optionreplace'
		*DiD
		reghdfe   D_`y'      $treatment     $var_93   $var_geo if sample==1  , abs(i.dep_id)  vce(robust)
				outreg2 $treatment  using table_main.xls, bdec(3)    `optionreplace'
 
						
}
 
  
* TABLE  4
***********************

 local optionreplace="replace"
  foreach y in     pipedwater sewage electricity   	poor gini       {
  	
	reghdfe   D_`y'     $treatment       $var_93   $var_geo     if sample==1 [pw= cpv17_pop], abs(i.dep_id)  vce(robust)
				outreg2 $treatment  using table_robust.xls, bdec(3)   `optionreplace'
					local optionreplace=""
	
	reghdfe   D_`y'     high_canon_9807_0916_p90        $var_93   $var_geo     if sample==1  , abs(i.dep_id)  vce(robust)
				outreg2    using table_robust.xls, bdec(3)   `optionreplace'
	
	reghdfe   D_`y'     high_canon_0916_p75        $var_93   $var_geo     if sample==1  , abs(i.dep_id)  vce(robust)
				outreg2    using table_robust.xls, bdec(3)   `optionreplace'
	
	reghdfe   D_`y'      $treatment       $var_93   $var_geo      , abs(i.dep_id)  vce(robust)
				outreg2    using table_robust.xls, bdec(3)   `optionreplace'

	 reghdfe   D_`y'      highcanon_n      $var_93   $var_geo   if sample==1    , abs(i.dep_id)  vce(robust)
				outreg2    using table_robust.xls, bdec(3)   `optionreplace'
				
}

* TABLE  5
***********************

	reghdfe   D_pipedwater   T  Txsierra Txhighrural Txhighneed Txlowsec Txshareprof99 share_prof99  sierra highrural highneed lowsec  $var_93   $var_geo if sample==1, abs(i.dep_id)  vce(robust)
   		 	outreg2 T  Txsierra Txhighrural Txhighneed Txshareprof99 Txlowsec using table_hetero.xls, bdec(3)   replace
			
	reghdfe   D_sewage   T  Txsierra Txhighrural Txhighneed Txlowsec  Txshareprof99 share_prof99 sierra highrural highneed lowsec  $var_93   $var_geo if sample==1, abs(i.dep_id)  vce(robust)
     		 outreg2 T  Txsierra Txhighrural Txhighneed Txshareprof99 Txlowsec using table_hetero.xls, bdec(3)    
			 
	reghdfe   D_electricity   T  Txsierra Txhighrural Txhighneed Txlowsec  Txshareprof99 share_prof99 sierra highrural highneed lowsec  $var_93   $var_geo if sample==1, abs(i.dep_id)  vce(robust)
      		 outreg2 T  Txsierra Txhighrural Txhighneed Txshareprof99 Txlowsec using table_hetero.xls, bdec(3)  
			 
	reghdfe   D_poor   T  Txsierra Txhighrural Txhighneed Txlowsec  Txshareprof99 share_prof99 sierra highrural highneed lowsec  $var_93   $var_geo if sample==1, abs(i.dep_id)  vce(robust)
	       		 outreg2 T  Txsierra Txhighrural Txhighneed Txshareprof99 Txlowsec using table_hetero.xls, bdec(3)   
				 
	reghdfe    D_gini   T  Txsierra Txhighrural Txhighneed Txlowsec  Txshareprof99 share_prof99 sierra highrural highneed lowsec  $var_93   $var_geo if sample==1, abs(i.dep_id)  vce(robust)
     		 outreg2 T  Txsierra Txhighrural Txhighneed Txshareprof99 Txlowsec using table_hetero.xls, bdec(3)    

   
* TABLE  6
***********************


 local optionreplace="replace"
 
 	foreach y in    avg_totalrevenue_0916_pc      n_workerspc    share_prof        n_carspc n_heavymachinpc  n_gestioninfo4 need_tech_18 need_train_18   high_tech18      high_train18        {
 
 
  
  
		reghdfe    `y'      $treatment     $var_93   $var_geo if sample==1, abs(i.dep_id)  vce(robust)
					cap outreg2 $treatment  using table_inputs.xls, bdec(3)   `optionreplace'
					local optionreplace=""
			
		reghdfe   `y'     $treatment  $var_93   $var_geo if sample==1, abs(i.boundary_id)  vce(robust)
					outreg2 using table_inputs.xls, bdec(3)   `optionreplace'
					
		bootstrap r(ate): psmatch2         $treatment   $var_93   $var_geo    if sample==1    , n(4) outcome(`y') common  ate
					outreg2 using table_inputs.xls, bdec(3)   `optionreplace'
	  
		reghdfe    D_`y'     $treatment       $var_93   $var_geo     if sample==1, abs(i.dep_id)  vce(robust)
					outreg2 $treatment  using table_inputs.xls, bdec(3)    `optionreplace'
	}


 

* TABLE  7
***********************


cap drop index_road
egen index_road=rmean( rep_pistas_m2_pc con_pistas_m2_pc rep_veredas_m2_pc con_veredas_m2_pc)


 local optionreplace="replace"
  foreach y in    rep_pistas_m2_pc con_pistas_m2_pc rep_veredas_m2_pc con_veredas_m2_pc   index_road       {
 
 		reghdfe   `y'      $treatment     $var_93   $var_geo if sample==1  , abs(i.dep_id)  vce(robust)
				outreg2 $treatment  using table_roads.xls, bdec(3)    `optionreplace'
				local optionreplace=""
 		reghdfe    `y'     $treatment  $var_93   $var_geo if sample==1  , abs(i.boundary_id)  vce(robust)
				outreg2 using table_roads.xls, bdec(3)   `optionreplace'
		bootstrap r(ate): psmatch2         $treatment   $var_93   $var_geo    if sample==1    , n(4) outcome(`y') common  ate
				outreg2 using table_roads.xls, bdec(3)   `optionreplace'

 
						
}
  
   
   

 
}
*


		 
 
